package com.hiwhitley.easy.day09;

/**
 * Created by hiwhitley on 2016/8/13.
 */
public class IsAnagram {
    public boolean isAnagram(String s, String t) {
        if (s.length() != t.length()) {
            return false;
        }
        int[] table = new int[26]; // only lowercase letters
        for (char c : s.toCharArray()) { // 字符计数
            table[c - 'a']++;
        }
        for (char c : t.toCharArray()) { // 递减字符计数
            table[c - 'a']--;
            if (table[c - 'a'] < 0) { // 字符短缺
                return false;
            }
        }
        return true;
    }
}
